import moment from 'moment'

// TODO 方法导出用export 可以批量

const newFormat = time => {
    let hours = Math.floor(moment().diff(time, 'hours', true) * 10) / 10
    const day = moment().diff(time, 'day')
    if (day === 0) {
        if (hours < 0.1) {
            return '刚刚'
        } else if (hours < 1) {
            return `${hours}小时前`
        }
        if (hours >= 1) {
            hours = parseInt(hours)
            return `${hours}小时前`
        }
    } else if (day === 1) {
        return `昨天`
    } else {
        return moment(time).format('YYYY-MM-DD HH:mm:ss')
    }
}
export default newFormat
